package chapter_02

class Test {
  def max(x: Int, y: Int): Int = {
    // 变量定义
    if (x > y) x else y
  }
  
  def show() {
    // 数组和列表
    val greetings = new Array[String](3)
    greetings(0) = "Hello"
    greetings(1) = ","
    greetings(2) = "World!\n"
    
    greetings.foreach(print)
    
    val my_list = List(1, 2)
    val new_list = 1 :: my_list
//    new_list.foreach(print)
    new_list.foreach(one => print(one + " "))
  }

  def tuple(): Unit = {
    // 元组
    var jetSet = ("Boeing", 99)
    println(jetSet._1)
    println(jetSet._2)
  }

  def set_func(): Unit = {
    // 集合
    var jetSet = Set("Boeing", "Airbus")
    jetSet += "Lear"
    println(jetSet.contains("Cessna"))
  }

  def map_func(): Unit = {
    // 映射
    // 默认是不可变的
    var aMap: Map[Int, String] = Map()
    aMap += 1->"Hello"
    aMap += 2->"World!"
    println(aMap(2))
  }
}


object chapter_02 {
  def main(args: Array[String]): Unit = {
    val t: Test = new Test()
//    println(t.max(10, 20))
    t.show()
//    t.tuple()
//    t.set_func()
//    t.map_func()
  }
}